#ifndef QGRAPHIC_H
#define QGRAPHIC_H

#include "QPoint.h"
#include "QRect.h"
//#include "QOsDefine.h"
#include "cx_typedef.h"
#include "QOsBase.h"

#define BPP16M 3
#define BPP64K 2

//class CQRectBitmap;
class CQBitmap;
class CQFont;
class CQColor;
class CQWString;
class CQShadowBitmap;
class CQGraphic
{

public:
    enum TQTextAlign
    {
        /** Text is left-aligned. */
        EQLeft,
        /** Text is centred. */
        EQCenter,
        /** Text is right-aligned. */
        EQRight
    };

    enum TQDrawModeComponents
    {
        /** 1 */
        EQInvertScreen=1,
        /** 2 */
        EQXor=2,
        /** 4 */
        EQOr=4,
        /** 8 */
        EQAnd=8,
        /** 14 */
        EQLogicalOp=14,
        /** 16 */
        EQInvertPen=16,
        /** 32 */
        EQPenmode=32,
        /** 64 */
        EQWriteAlpha=64,
    };

    enum TQDrawMode
    {
        /** Bitwise ANDs the pen and brush colours with the screen colour. 
        P=p&s, B=b&s */
        EQDrawModeAND=EQAnd,
        /** Inverts the pen and brush colours before ANDing. P=(~p)&s, 
        B=(~b)&s */
        EQDrawModeNOTAND=EQInvertScreen|EQAnd,
        /** Uses both pen and brush colour as they are. P=p, B=b */
        EQDrawModePEN=EQPenmode,
        /** Inverts the screen colour before ANDing. P=p&(~s), B=b&(~s) */
        EQDrawModeANDNOT=EQAnd|EQInvertPen,
        /** Bitwise XORs the pen and brush colours with the screen colour. 
        P=p^s, B=b^s */
        EQDrawModeXOR=EQXor,
        /** Bitwise ORs the pen and brush colours with the screen colour. 
        P=p|s, B=b|s */
        EQDrawModeOR=EQOr,
        /** Inverts the screen and pen and brush colours before ANDing. 
        P=(~p)&(~s), B=(~b)&(~s) */
        EQDrawModeNOTANDNOT=EQInvertScreen|EQAnd|EQInvertPen,
        /** Inverts the pen and brush colours before XORing. P=(~p)^s, 
        B=(~b)^s */
        EQDrawModeNOTXOR=EQInvertScreen|EQXor,
        /** Inverts the colour of each pixel that is drawn over, (pen and 
        brush attributes are ignored). P=~s, B=~s */
        EQDrawModeNOTSCREEN=EQInvertScreen,
        /** Inverts the pen and brush colours before ORing. P=(~p)|s, 
        B=(~b)|s */
        EQDrawModeNOTOR=EQInvertScreen|EQOr,
        /** Inverts the pen and brush colours. P=~p, B=~b */
        EQDrawModeNOTPEN=EQInvertPen|EQPenmode,
        /** Inverts the screen, pen and brush colours before ORing. P=p|(~s), 
        B=b|(~s) */
        EQDrawModeORNOT=EQOr|EQInvertPen,
        /** NOT OR NOT mode. P=(~p)|(~s), B=(~b)|(~s) */
        EQDrawModeNOTORNOT=EQInvertScreen|EQOr|EQInvertPen,
        /** Writes alpha information in the source directly into the destination, rather than blending. */
        EQDrawModeWriteAlpha=EQWriteAlpha,
    };


    enum TQPenStyle
    {
        /** The pen does not draw. Screen pattern unit = 00... */
        EQNullPen,
        /** A solid line (default). Screen pattern unit = 11... */
        EQSolidPen,
        /** A dotted line. Screen pattern unit = 1000... */
        EQDottedPen,
        /** A dashed line. Screen pattern unit = 111000... */
        EQDashedPen,
        /** A line of alternating dashes and dots. Screen pattern unit = 
        1111001100... */
        EQDotDashPen,
        /** A line of alternating single dashes and pairs of dots. Screen 
        pattern unit = 11110011001100... */
        EQDotDotDashPen
    };


    enum TQBrushStyle
    {
        /** The brush fill has no effect (default). */
        EQNullBrush,
        /** The brush fills with a solid single colour, determined by 
        SetBrushColor() and the drawing mode. */
        EQSolidBrush,
        /** The brush fills with a selected bitmap pattern, set by 
        UseBrushPattern(). */
        EQPatternedBrush,
        /** The brush fills with vertical hatching  lines going from top to 
        bottom. */
        EQVerticalHatchBrush,
        /** The brush fills with diagonal hatching lines going from bottom 
        left to top right. */
        EQForwardDiagonalHatchBrush,
        /** The brush fills with horizontal hatching  lines going from left 
        to right. */
        EQHorizontalHatchBrush,
        /** The brush fills with rearward diagonal hatching lines going from top 
        left to bottom right. */
        EQRearwardDiagonalHatchBrush,
        /** The brush fills with horizontal and vertical hatching  lines going 
        from left to right plus lines going from top to bottom  giving the 
        effect of a grid of small squares */
        EQSquareCrossHatchBrush,
        /** The brush fills with forward diagonal and rearward diagonal hatching 
        lines going from bottom left to top right plus lines going from top left 
        to bottom right giving the effect of a grid of small diamonds. */
        EQDiamondCrossHatchBrush
    };    


	enum TQArrowDirect
	{
		EQArrowUp,
		EQArrowDown,
		EQArrowLeft,
		EQArrowRight		
	};

public:
    IMPORT_C CQGraphic(CGraphicsContext* pGC, CBitmapDevice* pDevice, CFbsBitmap *pOffScreenBitmap, CFont* pFont = NULL);
    IMPORT_C virtual ~CQGraphic();

public:
	//IMPORT_C void ShadowMask(const CQRect& destRect, const CQColor& maskColor);
    IMPORT_C void DrawLine(const CQPoint &pt1, const CQPoint &pt2);
    IMPORT_C void DrawPoint(const CQPoint &pt);
    IMPORT_C void DrawRect(const CQRect &rt);
	IMPORT_C void DrawPolygon(const CQPoint* aPointList,QINT32 aNumPoints );
    //IMPORT_C void DrawBitmap(const CQPoint &pt, const CQRectBitmap* pBitmap);
    //IMPORT_C void DrawGrayBitmap(const CQPoint &pt, const CQRectBitmap* pBitmap);
    //IMPORT_C void DrawGrayBitmap(const CQPoint &pt, const CFbsBitmap* pFbsBitmap);
    //IMPORT_C void DrawBitmap(const CQRect &rt, const CQRectBitmap* pBitmap);
	//IMPORT_C void DrawBitmap(const CQRect &rtDest, const CQRectBitmap* pBitmap, const CQRect &rtSrc);
	//IMPORT_C void DrawBitmap(const CQPoint &pt, const CQRectBitmap* pBitmap, const CQRect &rtSrc);
	IMPORT_C void DrawBitmap(const CQPoint &pt, const CQBitmap* pBitmap);
	IMPORT_C void DrawBitmap(const CQPoint &pt, const CFbsBitmap* pBitmap);
	IMPORT_C void DrawBitmap(const CQPoint &pt, const CQBitmap* pBitmap,CQRect& aClipRect);
	IMPORT_C void DrawBitmapToFbsBitmapClip(const CQPoint &pt, const CQBitmap* pBitmap, CQRect aClipRect, QINT aScreenWidth, QINT aScreenHeight, TUint8* pDst, QBOOL bSetGray = QFALSE);
	IMPORT_C void DrawBitmap(const CQRect &rtDest, const CQBitmap* pBitmap, const CQRect &rtSrc);
//#ifdef __SERIES60_3X__
//	IMPORT_C void DrawBitmapMasked(const CQRect &rt, const CFbsBitmap* pBitmap, const CFbsBitmap* aMask);
//#endif
	//IMPORT_C void DrawBitmap(const CQRect &rt, const CFbsBitmap* pBitmap);
	//IMPORT_C void DrawBitmap(const CQRect &rtDest, const CFbsBitmap* pBitmap, const CQRect &rtSrc);
	//IMPORT_C void DrawBitmap(const CQRect &rt, const CQBitmap* pBitmap);
	//IMPORT_C void DrawBitmap(const CQRect &rtDest, const CQBitmap* pBitmap, const CQRect &rtSrc);
	//IMPORT_C void DrawBitmap(const CQPoint &pt, const CFbsBitmap* pFbsBitmap,const TRect &rt);
	//IMPORT_C void DrawGrayBitmap(const CQPoint &pt, const CQBitmap* pBitmap);
	
    //IMPORT_C void DrawText(const CQPoint &pt, const TDesC& text);
    IMPORT_C void DrawText(const CQPoint &pt, const CQWString& text);
    IMPORT_C void DrawText(const CQWString& aText,
                           const CQRect& aBox,
                           QINT32 aBaselineOffset,
                           TQTextAlign aAlignment = EQLeft, 
                           QINT32 aLeftMargin = 0);
    
//    IMPORT_C void DrawText(const TDesC &aText,
//                           const CQRect& aBox,
//                           QINT32 aBaselineOffset,
//                           TQTextAlign aAlignment = EQLeft, 
//                           QINT32 aLeftMargin = 0);
    
	IMPORT_C void DrawTextVertical(const CQWString& aText,const CQPoint& aPos,QBOOL aUp);
	IMPORT_C void DrawTextVertical(const CQWString& aText,const CQRect& aBox,QINT aBaselineOffset,QBOOL aUp,TQTextAlign aVert=EQLeft,QINT aMargin=0);
	//IMPORT_C void DrawTextVertical(const TDesC &aText,const CQRect& aBox,QINT aBaselineOffset,QBOOL aUp,TQTextAlign aVert=EQLeft,QINT aMargin=0);
	
    IMPORT_C void DrawArrow(CQRect& aRect, TQArrowDirect aDirect);
    
    //IMPORT_C void SetUnderlineStyle(QBOOL IsUnderlineStyleOn = QTRUE);	
    
    IMPORT_C void UseFont(const CQFont* aFont);
    IMPORT_C void DiscardFont();

	//IMPORT_C CQFont* GetDefaultFont();

    //IMPORT_C void SetDrawMode(TQDrawMode aDrawingMode);
	IMPORT_C void SetClippingRect(const CQRect &rt);
	//IMPORT_C void SetClippingRect(const TRect &rt);
	IMPORT_C void CancelClippingRect();

    //void SetOffset(const CQPoint &pt);
    //CQPoint GetOffset() const;
    //void SetClipBox(const CQRect &rt);
    //CQRect GetClipBox() const;

    IMPORT_C void SetPenColor(const CQColor &cr);
    IMPORT_C void SetPenSize(const CQSize &sz);
    IMPORT_C void SetPenStyle(TQPenStyle style);

    IMPORT_C void SetBrushColor(const CQColor &cr);
    IMPORT_C void SetBrushStyle(TQBrushStyle style);
//    IMPORT_C void SetBrushOrigin(const CQPoint &org);

    //IMPORT_C void MoveTo(const CQPoint &pt);
    //IMPORT_C void LineTo(const CQPoint &pt);

    IMPORT_C void DrawRoundRect(const CQRect &rt, const CQSize& cornerSize);
    //IMPORT_C void DrawEllipse(const CQRect &rt);
    IMPORT_C void DrawArrow(const CQPoint* ptlist);
    //void DrawString(const CQPoint &pt, const String &text, Font *pFont);
    //SizeI GetStringSize(const String &text, Font *pFont);
    //void DrawFocusRect(const CQRect &rt);
    //IMPORT_C void UseBrushPattern(const CQBitmap*  aPattern);
    //IMPORT_C void UseBrushPattern(const CFbsBitmap*  patBitmap);
    //IMPORT_C virtual void DiscardBrushPattern();


	//IMPORT_C void GetScreenSize(CQSize& sz);
	//IMPORT_C QINT32 FontHeightInPixels();
	//IMPORT_C QINT32 TextWidthInPixels(const CQWString& strText);

	//IMPORT_C void ResetDefaultColor();
	
	//IMPORT_C void ShadowBitmapToQRectBitmap(CQShadowBitmap* bmSrc, CQRectBitmap* bmDst);
	
	IMPORT_C void DrawShadowBitmap(CQRect aRect,CQShadowBitmap* pShadowBitmap);
	
protected:
	TUint8* GetScreenDataAddress();
	CFbsBitmapDevice* CreateBitmapDeviceL( CFbsBitmap& aBitmap );
	CFbsBitmapDevice* CreateBitmapDeviceLC( CFbsBitmap& aBitmap );
	CFbsBitGc* CreateGraphicsContextL( CFbsBitmapDevice& aBitmapDevice );
	CFbsBitGc* CreateGraphicsContextLC( CFbsBitmapDevice& aBitmapDevice );
public:
    CGraphicsContext* m_pGC;
    CFbsBitmap* m_pOffScreenBitmap;
private:
	void DrawBitmapToFbsBitmap(const CQPoint &pt, const CQBitmap* pBitmap,QINT abackWidth, QINT abackHeight, TUint8* pDst, QBOOL bSetGray = QFALSE);
	CGraphicsContext* GetGC();
    CBitmapDevice* m_pDevice;
    CFont*  m_pUsedFont;
    CFont*  m_pSavedFont;
    CQFont* m_pDefaultFont;
	CQSize  m_ScreenSize;
	
	CQRect  m_clipRect;
};

#endif //QGRAPHIC_H
